package com.mifengs.mall.floor;

import android.support.v7.widget.GridLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.View;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.chad.library.adapter.base.annotation.ItemProviderTag;
import com.chad.library.adapter.base.provider.BaseItemProvider;
import com.mifengs.mall.R;
import com.mifengs.mall.adapter.TwoFourItemAdapter;
import com.mifengs.mall.adapter.TwoGridtemAdapter;
import com.mifengs.mall.entity.AdvertBean;
import com.mifengs.mall.entity.FloorBean;
import com.mifengs.mall.util.ToIntentUtil;
import com.yqritc.recyclerviewflexibledivider.HorizontalDividerItemDecoration;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by lihaoqi on 2018/4/16.
 */

@ItemProviderTag(
        viewType = FloorListAdapter.TYPE_TWENTY_ONE,
        layout = R.layout.fragment_two_flo
)
public class FloorTwentyOneItemProvider extends BaseItemProvider<FloorBean,BaseViewHolder> {

    private TwoFourItemAdapter mTwoFourItemAdapter;
    private List<AdvertBean>  mList;
    @Override
    public void convert(BaseViewHolder helper, FloorBean floorBean, int position) {
        mList = new ArrayList<>();
        RecyclerView recyclerView = helper.getView(R.id.two_grid_list);
        if(floorBean !=null){
            for(int i = 0;i<2;i++){
                mList.add(floorBean.getAdverts().get(i));
            }
            recyclerView.setLayoutManager(new GridLayoutManager(mContext,2));
            recyclerView.setNestedScrollingEnabled(false);
            mTwoFourItemAdapter= new TwoFourItemAdapter(R.layout.item_two_four_floor,mList,mContext,1);
            recyclerView.setAdapter(mTwoFourItemAdapter);
            mTwoFourItemAdapter.setOnItemClickListener(new BaseQuickAdapter.OnItemClickListener() {
                @Override
                public void onItemClick(BaseQuickAdapter adapter, View view, int position) {
                    AdvertBean adverts = mList.get(position);
                    ToIntentUtil.toCommonIntent(adverts.getActionUrl(),mContext);
                }
            });
        }
    }

    @Override
    public void onClick(BaseViewHolder helper, FloorBean floorBean, int i) {

    }

    @Override
    public boolean onLongClick(BaseViewHolder helper, FloorBean floorBean, int i) {
        return false;
    }
}
